/*
 * File     : StructureOptions.java
 * Created  : 1 May 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.type.structure;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.nio.ByteBuffer;

import com.googlecode.dni.DirectNativeInterface;
import com.googlecode.dni.FixedSize;
import com.googlecode.dni.Library;
import com.googlecode.dni.Padding;


/**
 * <p>
 *  Annotates an interface to indicate that it is used as a structure.
 * </p>
 *
 * @see DirectNativeInterface#getStructureFactory(Class)
 *
 * @author Matthew Wilson
 */
@Retention( RetentionPolicy.RUNTIME )
@Target( ElementType.TYPE )
@Documented
public @interface StructureOptions
{

    /**
     * Special pseudo-character-set name for the default platform character set.
     */
    String DEFAULT_CHARSET = Library.DEFAULT_CHARSET;

    /**
     * <p>
     *  The size of the structure, in bytes.
     * </p>
     * <p>
     *  <em>Do not set this without good cause.</em>  The toolkit will
     *  automatically calculate the required size, including padding.  Use of
     *  explicit sizing implies you have explicitly set all
     *  {@linkplain FieldOffset field offsets}, and that you know the specifics
     *  of the alignment rules of your target platforms.
     * </p>
     *
     * @return the size, in bytes; or -1 to calculate automatically
     */
    int size() default -1;

    /**
     * <p>
     *  The character set name to use.
     * </p>
     * <p>
     *  By default, the platform character set is chosen.
     * </p>
     *
     * @return the character set name
     */
    String charset() default DEFAULT_CHARSET;

    /**
     * <p>
     *  The padding options for this structure.
     * </p>
     *
     * @return the padding options
     */
    Padding padding() default Padding.DEFAULT;

    /**
     * <p>
     *  Whether the structure is opaque.
     * </p>
     * <p>
     *  An opaque structure has an unknown size, and hence cannot be passed by
     *  value, cannot be used as a value in a struct, and cannot be copied;
     *  essentially, the structure becomes an opaque pointer of a specialised
     *  type.  The {@link Object#equals(Object)} and {@link Object#hashCode()}
     *  will work off the pointer only.
     * </p>
     * <p>
     *  To simulate an opaque structure of an explicit size, define a structure
     *  with a {@link FixedSize} {@link ByteBuffer}.
     * </p>
     *
     * @return <code>true</code> iff opaque
     */
    boolean opaque() default false;

}
